#pragma once

#include "CDependencyObject.h"




#include "TransformAndClipStack.h"

class CRenderTarget;
class HWFrameData;

class UIElementClone;


class HWCompTreeNode :
	public CDependencyObject
{
public: 
	static HRESULT Create(CRenderTarget * pRenderTarget, HWFrameData * pFrameData, CUIElement * pUIElement, const TransformAndClipStack * pPrependTransformsAndClips, XFLOAT prependOpacity, HWCompTreeNode * * ppHWCompositorTreeNode);
	void ResetIndependentInfoSlotRange();
	void AddPrimitiveSlot(XUINT32 slot);
	struct HWDMData * GetDMData();
	HRESULT CalculateObjectWorldProperties(const TransformAndClipStack * pLocalTransformsAndClips, XFLOAT localOpacity, TransformAndClipStack * pWorldTransformsAndClips, XFLOAT * pWorldOpacity);
	HRESULT GetWorldTransformsAndClips(TransformAndClipStack * pTransformsAndClips);
	XBOOL IsInBounds(const struct XRECTF_WH & localSpaceRect);
	HRESULT RenderTree(const struct XRECTF_WH & backBuffer);
	HRESULT AddChild(HWCompTreeNode * pChild);
	XBOOL IsTreeDirty();
	static void NWSetDirty(CDependencyObject * pTarget, enum DirtyFlags::Value flags);
	virtual XUINT32 GetTypeIndex() const;
	HWFrameData * GetFrameData();

protected: 
	HWCompTreeNode(CCoreServices *, HWFrameData *, XFLOAT);
	virtual ~HWCompTreeNode();
	HRESULT Initialize(CRenderTarget * pRenderTarget, CUIElement * pUIElement, const TransformAndClipStack * pPrependTransformsAndClips);
	virtual HRESULT PushPropertiesVirtual(const struct CompositionParams * pParentContext, TransformAndClipStack * pCurrentTransformsAndClips, XFLOAT * pCurrentOpacity, HWClip * pCumulativeClipLocalSpace);
	virtual HRESULT ApplyRenderProperties(XBOOL firstDraw, const TransformAndClipStack * pTransformsAndClips, XFLOAT opacity);
	HRESULT PushProperties(TransformAndClipStack * pRedirectedWorldTransforms, const struct CompositionParams * pParentContext, TransformAndClipStack * pCurrentTransformsAndClips, XFLOAT * pCurrentOpacity, HWClip * pCumulativeClipLocalSpace);
private: 
	HRESULT UpdateTree(const struct CompositionParams & treeContext);
	XFLOAT GetDirectManipulationTranslationX();
	XFLOAT GetDirectManipulationTranslationY();
	XFLOAT GetDirectManipulationZoomFactor();
	HRESULT ApplyLocalClips(TransformAndClipStack * pTransformsAndClips, HWClip * pCumulativeClipLocalSpace);
	HRESULT ApplyLocalProjection(TransformAndClipStack * pTransformsAndClips, HWClip * pCumulativeClipLocalSpace);
	UIElementClone * m_pCloneUIE;
	TransformAndClipStack * m_pPrependTransformsAndClips;
	XFLOAT m_prependOpacity;
	TransformAndClipStack m_worldTransformsAndClips; 



private: 
	XFLOAT m_worldOpacity;
	HWClip m_cumulativeClipLocalSpace;  



private: 
	XUINT32 m_independentInfoSlotStart;
	XUINT32 m_independentInfoSlotEnd;
	HWFrameData * m_pFrameData;
	struct HWDMData * m_pDMData;
	XBOOL m_firstDraw;
	XBOOL m_isDirtyForRender;
	xvector<HWCompTreeNode *> m_children;  




};


